package org.yunzhong.commontool;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.yunzhong.commontool.service.HolidayApplyService;
import org.yunzhong.commontool.util.ParameterTool;

@SpringBootApplication
public class CommontoolApplication {

    public static void main(String[] args) throws IOException {
        Map<String, String> argMap = ParameterTool.fromArgs(args);
        SpringApplication.run(CommontoolApplication.class, args);
        if (argMap != null && !argMap.isEmpty()) {
            String excel = argMap.get("excel");
            String doc = argMap.get("doc");
            String date = argMap.get("date");
            Path excelPath = Paths.get(excel);
            Path docPath = Paths.get(doc);
            HolidayApplyService holidayApplyService = new HolidayApplyService();
            if (StringUtils.isNotEmpty(date)) {
                try {
                    holidayApplyService.generate(excelPath, docPath, date);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                try {
                    holidayApplyService.generate(excelPath, docPath);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            System.exit(1);
        }
    }

}
